﻿using TMS.Model;

namespace TMS.DAL
{
    public class RoomDal
    {
        public RoomDal(MyContent myContent)
        {
            MyContent = myContent;
        }

        public MyContent MyContent { get; }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="Roomtype"></param>
        /// <returns></returns>
        public int Add(Roomtype Roomtype)
        {
            MyContent.Roomtype.Add(Roomtype);
            return MyContent.SaveChanges();
        }
        /// <summary>
        /// 查询房型名称是否重复
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public int checkname(string name)
        {
            int res=MyContent.Roomtype.Where(x => x.Rname == name).Count();
            return res;
        }
        /// <summary>
        /// 显示
        /// </summary>
        /// <returns></returns>
        public List<Roomtype> GetRoomtype()
        {
            List<Roomtype> Roomtype = MyContent.Roomtype.ToList();
           return Roomtype;
        }
        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Roomtype Fantian(int id)
        {
            var model=MyContent.Roomtype.Find(id);
            return model;
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="Roomtype"></param>
        /// <returns></returns>
        public int Update(Roomtype Roomtype)
        {
            var model = MyContent.Roomtype.Find(Roomtype.ID);
            model.Rname=Roomtype.Rname;
            model.Remark=Roomtype.Remark;
            return MyContent.SaveChanges();
        }
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="states"></param>
        /// <returns></returns>
        public int upda(int id,int states)
        {
            var model = MyContent.Roomtype.Find(id);
            model.Stets = states;
            return MyContent.SaveChanges();
        }
        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int delete(int id)
        {
            var model=MyContent.Roomtype.Find(id);
            model.Isdel = true;
            return MyContent.SaveChanges();
        }
    }
}
